<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绑定属性</title>
    <style>
        .my{
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <div id="div">
        <img v-bind:src="imgUrl">
        <img :src="imgUrl">
        <br>
        <button type="button" @click="changeImg()">随机切换图片</button>
    </div>
</body>
<script src="js/vue.js"></script>
<script>

    let vue=new Vue({
        el:"#div",
        data:{
            imgUrl:"img/01.jpg",
            imgs : [
                "img/01.jpg",
                "img/02.jpg",
                "img/03.jpg",
                "img/04.jpg",
                "img/05.jpg",
                "img/06.jpg",
                "img/07.jpg",
                "img/08.jpg",
                "img/09.jpg",
                "img/10.jpg"]
        },
        methods:{
            changeImg(){
                //需求：每次点击按钮之后都随机切换一张图片
                //1 随机生成一个索引[0,9]整数   Math.random()*10-->[0,10)
                let index = Math.floor(Math.random()*10);
                //2 根据索引取出图片，赋值给imgUrl变量
                vue.imgUrl=this.imgs[index];
            }
        }
    });


</script>
</html>